//
//  IGArtCardCell.m
//  jingdongfang
//
//  Created by BOE on 2017/12/14.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGArtCardCell.h"
#import "IGArtWorksCardView.h"
#import "XiangQingViewController.h"
#import "IGTopicModel.h"

static NSString *const kIGArtCardCellID = @"kIGArtCardCellID";

@interface IGArtCardCell()

@property (nonatomic, strong) IGArtWorksCardView *artWorksCardView;

@end

@implementation IGArtCardCell

+ (IGArtCardCell *)cellWithTableView:(UITableView *)tableView {
    IGArtCardCell *cell = [tableView dequeueReusableCellWithIdentifier:kIGArtCardCellID];
    if (!cell) {
        cell = [[IGArtCardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kIGArtCardCellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor c3Color];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}

- (void)createUI {
    //关联的作品
    self.artWorksCardView = [IGArtWorksCardView new];
    self.artWorksCardView.backgroundColor = [UIColor mainBackgroundColor];
    self.artWorksCardView.userInteractionEnabled = YES;
    [self.contentView addSubview:self.artWorksCardView];
    [self.artWorksCardView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kGAP15);
        make.right.mas_equalTo(-kGAP15);
    }];
    
    __weak typeof(self) weakSelf = self;
    [self.artWorksCardView setTapActionWithBlock:^{
        XiangQingViewController *vc = [[XiangQingViewController alloc] init];
        vc.p_id = weakSelf.feedDetail.product.artId;
        vc.isRoot = YES;
        [UIViewController ig_pushViewController:vc animated:YES];
    }];
}

- (void)setFeedDetail:(IGTopicModel *)feedDetail {
    _feedDetail = feedDetail;
    if (![feedDetail.product.artId isEqualToString:@""] && feedDetail.product.artId) {
        self.artWorksCardView.hidden = false;
        IGArtWorksModel *artWorksModel = feedDetail.product;
        [self.artWorksCardView setModel:artWorksModel];
    } else {
        self.artWorksCardView.hidden = true;
    }
    
    [self.artWorksCardView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.height.mas_equalTo([IGArtCardCell cellHeight] - kGAP15);
    }];
    
}

+ (CGFloat)cellHeight {
    return 65 + kGAP15;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
